package com.sitecsys.controller;


import com.alibaba.fastjson2.JSONObject;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping("/api/sac")
public class SACController {


    private final RestTemplate restTemplate;

    public SACController() {
        this.restTemplate = new RestTemplate();
    }

    @PostMapping("/new_sac_lstm")
    public ResponseEntity<String> sendParamsToDjango(@RequestBody String requestBody) {
        try {

            String djangoApiUrl = "http://localhost:8000/new_sac_lstm/";
            // 将请求体转发给Django
            ResponseEntity<String> responseFromDjango = restTemplate.postForEntity(djangoApiUrl, requestBody, String.class);

            // 将Django的响应转发给前端
            return ResponseEntity.ok(responseFromDjango.getBody());
        } catch (Exception e) {
            // 处理可能发生的异常
            e.printStackTrace();
            return ResponseEntity.badRequest().body("Error forwarding request to Django");
        }
    }
    @PostMapping("/new_sac_r2n2")
    public ResponseEntity<String> sendParamsToDjango2(@RequestBody String requestBody) {
        try {

            String djangoApiUrl = "http://localhost:8000/new_sac_r2n2/";
            // 将请求体转发给Django
            ResponseEntity<String> responseFromDjango = restTemplate.postForEntity(djangoApiUrl, requestBody, String.class);

            // 将Django的响应转发给前端
            return ResponseEntity.ok(responseFromDjango.getBody());
        } catch (Exception e) {
            // 处理可能发生的异常
            e.printStackTrace();
            return ResponseEntity.badRequest().body("Error forwarding request to Django");
        }
    }
}
